package com.gxtbindings.bindings.client;

import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.store.ListStore;

/**
 * Utility methods for BeanModel based ListStore's
 * 
 * @author Jonathan Janisch
 *
 */
public class BeanModelStoreUtil {

	/**
	 * Finds the BeanModel in the store where model.getBean() equals the given bean.
	 * Returns null if no model was found
	 * 
	 * @param store the store to search
	 * @param bean the bean whose model we're looking for
	 * @return	the beanmodel if found, null otherwise.
	 */
	public static BeanModel findModel(ListStore<BeanModel> store, Object bean)
	{
		for (BeanModel storeBeanModel : store.getModels())
		{
			if (storeBeanModel.getBean().equals(bean))
			{
				return storeBeanModel;
			}
		}
		return null;
	}
}
